<?php 
if(!isset($_SESSION['tkemail'])){
		if(!isset($_COOKIE['role'])){
			//$_SESSION['action']='entry';
			header( 'Location: index.php?action=entry' );
		}else{
			$_SESSION['tkemail']=$_COOKIE["tkemail"];
		    $_SESSION['role']=$_COOKIE["role"];
			
			$role=$_SESSION['role'];
			$tkemail=$_SESSION['tkemail'];
		}
	}else{
		$role=$_SESSION['role'];
		$tkemail=$_SESSION['tkemail'];
	}
	if($tkemail==""){
		header( 'Location: index.php?action=entry' );
	}

?>
<link rel="stylesheet" type="text/css" href="js/jsDatePick_ltr.min.css" />
<link
	rel="stylesheet" type="text/css" href="css/style-login.css" />
<script
	type="text/javascript" src="js/jsDatePick.min.1.3.js"></script>
<script
	type="text/javascript"
	src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<link  href="css/jsDatePick_ltr.min.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="css/jsDatePick.min.1.3.js"></script>
<script type="text/javascript">
function getCalendar(){
	new JsDatePick({
		useMode:2,
		target:"searchfrom",

		dateFormat:"%Y-%m-%d"
	});
	new JsDatePick({
		useMode:2,
		target:"searchto",

		dateFormat:"%Y-%m-%d"
	});
}
window.onload = getCalendar();
</script>
<?php include 'connection/connection.php';?>
<?php 

	$lang=$_SESSION['lang'];
	if($lang=='')
			$lang='EN';
	
	if ( !isset($_REQUEST['page'] ))
	{
    	$page = 1 ;
	}else{
		$page = $_REQUEST['page'] ;
	}
	
	if ( !isset($_REQUEST['page'] ))
	{
		$list["email"]="DESC";
		$list["ins_time"]="DESC";
		$list["login"] = "DESC";
		
		$str="ins_time";
		$_SESSION['sortn']=$str;
		$_SESSION['sort']=$list;
	}else{
		$str=$_SESSION['sortn'];
		$list=$_SESSION['sort'];
	}
	
	$rows_per_page = 20;
	$page_start = ( $page - 1 ) * $rows_per_page; 
	$page_end = $page * $rows_per_page;
	
	$datecurrent = date("Y-m-d");
	
	$sql =  "select m.*,n.* from (select ss.* from (SELECT lv.*,ui.email
			FROM `user_info` ui, log_viewer lv 
			WHERE lv.id = ui.id AND lv.`status` = 'login' 
			
			ORDER BY ins_time DESC) as ss GROUP BY ss.id) as m,
			
			(SELECT aa.* from (SELECT user_info.id,
			(SELECT count(log_viewer.id) from log_viewer where user_info.id=log_viewer.id and log_viewer.`status`='login' 
					and log_viewer.ins_time >'".$datecurrent." 00:00:00' AND log_viewer.ins_time<'".$datecurrent." 23:59:59' ) as login,
			(SELECT count(log_viewer.id) from log_viewer where user_info.id=log_viewer.id and log_viewer.`status`='logout' 
					and log_viewer.ins_time >'".$datecurrent." 00:00:00' AND log_viewer.ins_time<'".$datecurrent." 23:59:59') as logout 
			from user_info) as aa ) as n 
			WHERE m.id=n.id ";
$selectuserlogin = mysql_query($sql." ORDER BY ".$str." ".$list[$str]);
$number_of_page = ceil ( mysql_num_rows( $selectuserlogin ) / $rows_per_page ); 
$_SESSION['sort']=$list;
?>
<script type="text/javascript">
// 2 buttons
// process button logining
function onclickDetailemail(iduser,emails){
	var lang = '<?=$_SESSION['lang']?>';
	$.ajax({url:"new-processlogviewer/view_detail_email_loginviewer.php?iduser="+iduser+"&emails="+emails+"&newlang="+lang, success:function(result){
		document.getElementById("idlogviewer").innerHTML=result;
	}});
}
function onclickUserLogining(){
	document.getElementById('buttonuserloginday').setAttribute("class", "buttonNormal");
	document.getElementById('buttonuserlogin').setAttribute("class", "buttonNormalchoose");
	document.getElementById('buttonlstemailyesterday').setAttribute("class", "buttonNormal");
	var lang = '<?=$_SESSION['lang']?>';
	$.ajax({url:"new-processlogviewer/content-userlogining.php",data : {newlang : lang}, success:function(result){
		document.getElementById("idlogviewer").innerHTML=result;
	}});
}
function pagingLogingUser(page,string,flagDesc){
	$.ajax({url:"new-processlogviewer/pagingLogingUserDetail.php", data : {pages : page,string : string,flagDesc : flagDesc}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

// new
function ajaxSearchLogViewerByOneDay_Loging(page,search,searchOneDay,emails){
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";

	document.getElementById('search').setAttribute("class", "buttonNormal");
	document.getElementById('searchAll').setAttribute("class", "buttonNormal");
	document.getElementById('search2day').setAttribute("class", "buttonNormal");
	document.getElementById('search1week').setAttribute("class", "buttonNormal");
	document.getElementById('search1month').setAttribute("class", "buttonNormal");
	document.getElementById('searchone').setAttribute("class", "buttonNormalchoose");
	
	$.ajax({url:"new-processlogviewer/ajaxSearchLogViewerByOneDay_Loging.php", data : {pages : page,search : search,searchOneDay : searchOneDay,emails : emails}, success:function(result){
		//$("table#tbLogViewer tr:not(:first)").remove();
		//$("table#tbLogViewer thead").append(result);
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}
function sortandpagingViewerOneDay_Loging(page,string,flagDesc,search,from,to,oneday,twodays,oneweek,onemonth,emails){
	$.ajax({url:"new-processlogviewer/sortandpagingViewerOneDay_Loging.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function ajaxSearchLogViewerBy2Day_Logining(page,search,searchcurrent,searchlast2day,emails){
	document.getElementById('searchfrom').value = "<?php echo date('Y-m-d',strtotime(date('Y-m-d').'-1 days'));?>";
	document.getElementById('searchto').value = "<?php echo date('Y-m-d');?>";

	document.getElementById('search').setAttribute("class", "buttonNormal");
	document.getElementById('searchAll').setAttribute("class", "buttonNormal");
	document.getElementById('search2day').setAttribute("class", "buttonNormalchoose");
	document.getElementById('search1week').setAttribute("class", "buttonNormal");
	document.getElementById('search1month').setAttribute("class", "buttonNormal");
	document.getElementById('searchone').setAttribute("class", "buttonNormal");
	
	$.ajax({url:"new-processlogviewer/ajaxSearchLogViewerByTwoDay_Logining.php", data : {pages : page,search : search,searchcurrent : searchcurrent,searchlast2day : searchlast2day,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function sortandpagingViewer2Day_Loging(page,string,flagDesc,search,from,to,oneday,twodays,oneweek,onemonth,emails){
	document.getElementById('searchfrom').value = "<?php echo date('Y-m-d',strtotime(date('Y-m-d').'-1 days'));?>";
	document.getElementById('searchto').value = "<?php echo date('Y-m-d');?>";
	
	$.ajax({url:"new-processlogviewer/sortandpagingViewer2Day_Loging.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function ajaxSearchLogViewerBy7Day_Logining(page,search,searchcurrent,searchlast7day,emails){
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";

	document.getElementById('search').setAttribute("class", "buttonNormal");
	document.getElementById('searchAll').setAttribute("class", "buttonNormal");
	document.getElementById('search2day').setAttribute("class", "buttonNormal");
	document.getElementById('search1week').setAttribute("class", "buttonNormalchoose");
	document.getElementById('search1month').setAttribute("class", "buttonNormal");
	document.getElementById('searchone').setAttribute("class", "buttonNormal");
	
	$.ajax({url:"new-processlogviewer/ajaxSearchLogViewerByOneWeek_Logining.php", data : {pages : page,search : search,searchcurrent : searchcurrent,searchlast7day : searchlast7day,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function sortandpagingViewer7Day_Loging(page,string,flagDesc,search,from,to,oneday,twodays,oneweek,onemonth,emails){
	$.ajax({url:"new-processlogviewer/sortandpagingViewerOneWeek_Loging.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function ajaxSearchLogViewerBy1Month_Logining(page,search,searchcurrent,searchlast1month,emails){
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";

	document.getElementById('search').setAttribute("class", "buttonNormal");
	document.getElementById('searchAll').setAttribute("class", "buttonNormal");
	document.getElementById('search2day').setAttribute("class", "buttonNormal");
	document.getElementById('search1week').setAttribute("class", "buttonNormal");
	document.getElementById('search1month').setAttribute("class", "buttonNormalchoose");
	document.getElementById('searchone').setAttribute("class", "buttonNormal");
	
	$.ajax({url:"new-processlogviewer/ajaxSearchLogViewerBy1Month_Logining.php", data : {pages : page,search : search,searchcurrent : searchcurrent,searchlast1month : searchlast1month,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function sortandpagingViewer1Month_Loging(page,string,flagDesc,search,from,to,oneday,twodays,oneweek,onemonth,emails){
	$.ajax({url:"new-processlogviewer/sortandpagingViewer1Month_Loging.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function ajaxSearchLogViewerByAll_Logining(page,search,emails){
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";

	document.getElementById('search').setAttribute("class", "buttonNormal");
	document.getElementById('searchAll').setAttribute("class", "buttonNormalchoose");
	document.getElementById('search2day').setAttribute("class", "buttonNormal");
	document.getElementById('search1week').setAttribute("class", "buttonNormal");
	document.getElementById('search1month').setAttribute("class", "buttonNormal");
	document.getElementById('searchone').setAttribute("class", "buttonNormal");
	
	$.ajax({url:"new-processlogviewer/ajaxSearchLogViewerByAll_Logining.php", data : {pages : page,search : search,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function sortandpagingViewerAll_Loging(page,string,flagDesc,search,from,to,oneday,twodays,oneweek,onemonth,emails){
	$.ajax({url:"new-processlogviewer/sortandpagingViewerAll_Loging.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}
function ajaxSearchLogViewer_Logining(page,search,emails){
	var searchfrom = $('input#searchfrom').val();
	var searchto = $('input#searchto').val();
	
	document.getElementById('search').setAttribute("class", "buttonNormalchoose");
	document.getElementById('searchAll').setAttribute("class", "buttonNormal");
	document.getElementById('search2day').setAttribute("class", "buttonNormal");
	document.getElementById('search1week').setAttribute("class", "buttonNormal");
	document.getElementById('search1month').setAttribute("class", "buttonNormal");
	document.getElementById('searchone').setAttribute("class", "buttonNormal");
	
	$.ajax({url:"new-processlogviewer/ajaxSearchLogViewer_Logining.php", data : {pages : page,search : search,searchfrom : searchfrom,searchto : searchto,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function sortandpagingViewer_Loging(page,string,flagDesc,search,from,to,oneday,twodays,oneweek,onemonth,emails){
	$.ajax({url:"new-processlogviewer/sortandpagingViewer_Loging.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

// process button user login in day
function onclickUserLoginInDay(){ 
	document.getElementById('buttonuserlogin').setAttribute("class", "buttonNormal");
	document.getElementById('buttonuserloginday').setAttribute("class", "buttonNormalchoose");
	document.getElementById('buttonlstemailyesterday').setAttribute("class", "buttonNormal");
	var lang = '<?=$_SESSION['lang']?>';
	$.ajax({url:"new-processlogviewer/content-userlogininday.php",data : {newlang : lang}, success:function(result){
		document.getElementById("idlogviewer").innerHTML=result;
	}});
}
function onclickDetailEmailLoginInDay(iduser,emails){
	var lang = '<?=$_SESSION['lang']?>';
	$.ajax({url:"new-processlogviewer/view_detail_email_logininday.php?iduser="+iduser+"&emails="+emails+"&newlang="+lang, success:function(result){
		document.getElementById("idlogviewer").innerHTML=result;
	}});
}

function pagingLogindayUser(page,string,flagDesc){
	$.ajax({url:"new-processlogviewer/pagingLoginDayUserDetail.php", data : {pages : page,string : string,flagDesc : flagDesc}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function ajaxSearchLogViewerByOneDay_LoginInDay(page,search,searchOneDay,emails){
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";

	document.getElementById('search').setAttribute("class", "buttonNormal");
	document.getElementById('searchAll').setAttribute("class", "buttonNormal");
	document.getElementById('search2day').setAttribute("class", "buttonNormal");
	document.getElementById('search1week').setAttribute("class", "buttonNormal");
	document.getElementById('search1month').setAttribute("class", "buttonNormal");
	document.getElementById('searchone').setAttribute("class", "buttonNormalchoose");
	
	$.ajax({url:"new-processlogviewer/ajaxSearchLogViewerByOneDay_LoginInDay.php", data : {pages : page,search : search,searchOneDay : searchOneDay,emails : emails}, success:function(result){
		//$("table#tbLogViewer tr:not(:first)").remove();
		//$("table#tbLogViewer thead").append(result);
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}
function sortandpagingViewerOneDay_LoginInDay(page,string,flagDesc,search,from,to,oneday,twodays,oneweek,onemonth,emails){
	$.ajax({url:"new-processlogviewer/sortandpagingViewerOneDay_LoginInDay.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function ajaxSearchLogViewerBy2Day_LoginInDay(page,search,searchcurrent,searchlast2day,emails){
	document.getElementById('searchfrom').value = "<?php echo date('Y-m-d',strtotime(date('Y-m-d').'-1 days'));?>";
	document.getElementById('searchto').value = "<?php echo date('Y-m-d');?>";

	document.getElementById('search').setAttribute("class", "buttonNormal");
	document.getElementById('searchAll').setAttribute("class", "buttonNormal");
	document.getElementById('search2day').setAttribute("class", "buttonNormalchoose");
	document.getElementById('search1week').setAttribute("class", "buttonNormal");
	document.getElementById('search1month').setAttribute("class", "buttonNormal");
	document.getElementById('searchone').setAttribute("class", "buttonNormal");
	
	$.ajax({url:"new-processlogviewer/ajaxSearchLogViewerByTwoDay_LoginInDay.php", data : {pages : page,search : search,searchcurrent : searchcurrent,searchlast2day : searchlast2day,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function sortandpagingViewer2Day_LoginInDay(page,string,flagDesc,search,from,to,oneday,twodays,oneweek,onemonth,emails){
	document.getElementById('searchfrom').value = "<?php echo date('Y-m-d',strtotime(date('Y-m-d').'-1 days'));?>";
	document.getElementById('searchto').value = "<?php echo date('Y-m-d');?>";
	
	$.ajax({url:"new-processlogviewer/sortandpagingViewer2Day_LoginInDay.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function ajaxSearchLogViewerBy7Day_LoginInDay(page,search,searchcurrent,searchlast7day,emails){
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";

	document.getElementById('search').setAttribute("class", "buttonNormal");
	document.getElementById('searchAll').setAttribute("class", "buttonNormal");
	document.getElementById('search2day').setAttribute("class", "buttonNormal");
	document.getElementById('search1week').setAttribute("class", "buttonNormalchoose");
	document.getElementById('search1month').setAttribute("class", "buttonNormal");
	document.getElementById('searchone').setAttribute("class", "buttonNormal");
	
	$.ajax({url:"new-processlogviewer/ajaxSearchLogViewerByOneWeek_LoginInDay.php", data : {pages : page,search : search,searchcurrent : searchcurrent,searchlast7day : searchlast7day,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function sortandpagingViewer7Day_LoginInDay(page,string,flagDesc,search,from,to,oneday,twodays,oneweek,onemonth,emails){
	$.ajax({url:"new-processlogviewer/sortandpagingViewerOneWeek_LoginInDay.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function ajaxSearchLogViewerBy1Month_LoginInDay(page,search,searchcurrent,searchlast1month,emails){
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";

	document.getElementById('search').setAttribute("class", "buttonNormal");
	document.getElementById('searchAll').setAttribute("class", "buttonNormal");
	document.getElementById('search2day').setAttribute("class", "buttonNormal");
	document.getElementById('search1week').setAttribute("class", "buttonNormal");
	document.getElementById('search1month').setAttribute("class", "buttonNormalchoose");
	document.getElementById('searchone').setAttribute("class", "buttonNormal");
	
	$.ajax({url:"new-processlogviewer/ajaxSearchLogViewerBy1Month_LoginInDay.php", data : {pages : page,search : search,searchcurrent : searchcurrent,searchlast1month : searchlast1month,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function sortandpagingViewer1Month_LoginInDay(page,string,flagDesc,search,from,to,oneday,twodays,oneweek,onemonth,emails){
	$.ajax({url:"new-processlogviewer/sortandpagingViewer1Month_LoginInDay.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function ajaxSearchLogViewerByAll_LoginInDay(page,search,emails){
	document.getElementById('search').setAttribute("class", "buttonNormal");
	document.getElementById('searchAll').setAttribute("class", "buttonNormalchoose");
	document.getElementById('search2day').setAttribute("class", "buttonNormal");
	document.getElementById('search1week').setAttribute("class", "buttonNormal");
	document.getElementById('search1month').setAttribute("class", "buttonNormal");
	document.getElementById('searchone').setAttribute("class", "buttonNormal");
	
	$.ajax({url:"new-processlogviewer/ajaxSearchLogViewerByAll_LoginInDay.php", data : {pages : page,search : search,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function sortandpagingViewerAll_LoginInDay(page,string,flagDesc,search,from,to,oneday,twodays,oneweek,onemonth,emails){
	$.ajax({url:"new-processlogviewer/sortandpagingViewerAll_LoginInDay.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function ajaxSearchLogViewer_LoginInDay(page,search,emails){
	var searchfrom = $('input#searchfrom').val();
	var searchto = $('input#searchto').val();
	
	document.getElementById('search').setAttribute("class", "buttonNormalchoose");
	document.getElementById('searchAll').setAttribute("class", "buttonNormal");
	document.getElementById('search2day').setAttribute("class", "buttonNormal");
	document.getElementById('search1week').setAttribute("class", "buttonNormal");
	document.getElementById('search1month').setAttribute("class", "buttonNormal");
	document.getElementById('searchone').setAttribute("class", "buttonNormal");
	
	$.ajax({url:"new-processlogviewer/ajaxSearchLogViewer_LoginInDay.php", data : {pages : page,search : search,searchfrom : searchfrom,searchto : searchto,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

function sortandpagingViewer_LoginInDay(page,string,flagDesc,search,from,to,oneday,twodays,oneweek,onemonth,emails){
	$.ajax({url:"new-processlogviewer/sortandpagingViewer_LoginInDay.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}

//list email is used yesterday
function onclickListEmailUseYesterday(){
	document.getElementById('buttonuserlogin').setAttribute("class", "buttonNormal");
	document.getElementById('buttonuserloginday').setAttribute("class", "buttonNormal");
	document.getElementById('buttonlstemailyesterday').setAttribute("class", "buttonNormalchoose");
	var lang = '<?=$_SESSION['lang']?>';

	$.ajax({url:"lstemail-yesterday/content-lstemail-used-yesterday.php",data : {newlang : lang}, success:function(result){
		document.getElementById("idlogviewer").innerHTML=result;
	}});
}
function sortAndPagingListEmailUsedYesterday(page,string,flagDesc){
	var lang = '<?=$_SESSION['lang']?>';
	$.ajax({url:"lstemail-yesterday/sortAndPagingListEmailUsedYesterday.php",data : {pages : page,string : string,flagDesc : flagDesc,newlang : lang},success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
		}
	});
}
function onclickDetailLstEmailUsedYesterday(iduser,emails){
	var lang = '<?=$_SESSION['lang']?>';
	$.ajax({url:"lstemail-yesterday/view-detail-email-used-yesterday.php?iduser="+iduser+"&emails="+emails+"&newlang="+lang, success:function(result){
		document.getElementById("idlogviewer").innerHTML=result;
	}});
}

function onclickButton_yesterday(page,string,dateyesterday,emails){
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";
	
	document.getElementById('search').setAttribute("class", "buttonNormal");
	document.getElementById('searchAll').setAttribute("class", "buttonNormal");
	document.getElementById('search2day').setAttribute("class", "buttonNormal");
	document.getElementById('search1week').setAttribute("class", "buttonNormal");
	document.getElementById('search1month').setAttribute("class", "buttonNormal");
	document.getElementById('searchone').setAttribute("class", "buttonNormal");
	document.getElementById('searchyesterday').setAttribute("class", "buttonNormalchoose");

	var status = document.getElementById('status').value ;
	$.ajax({url:"lstemail-yesterday/button_yesterday.php?pages="+page+"&str="+string+"&dateyesterday="+dateyesterday+"&emails="+emails+"&statuss="+status,success:function(result){
			$("table#tbLogViewer").empty();
			$("table#tbLogViewer").append(result);
		}
	});
}
function onclickButton_1_day(page,string,datecurrent,emails){
	document.getElementById('search').setAttribute("class", "buttonNormal");
	document.getElementById('searchAll').setAttribute("class", "buttonNormal");
	document.getElementById('search2day').setAttribute("class", "buttonNormal");
	document.getElementById('search1week').setAttribute("class", "buttonNormal");
	document.getElementById('search1month').setAttribute("class", "buttonNormal");
	document.getElementById('searchone').setAttribute("class", "buttonNormalchoose");
	document.getElementById('searchyesterday').setAttribute("class", "buttonNormal");

	var status = document.getElementById('status').value ;
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";
	
	$.ajax({url:"lstemail-yesterday/button-1-day.php?pages="+page+"&str="+string+"&datecurrent="+datecurrent+"&emails="+emails+"&statuss="+status,success:function(result){
			$("table#tbLogViewer").empty();
			$("table#tbLogViewer").append(result);
		}
	});
}
function onclickButton_2_days(page,string,datecurrent,twodays,emails){
	document.getElementById('search').setAttribute("class", "buttonNormal");
	document.getElementById('searchAll').setAttribute("class", "buttonNormal");
	document.getElementById('search2day').setAttribute("class", "buttonNormalchoose");
	document.getElementById('search1week').setAttribute("class", "buttonNormal");
	document.getElementById('search1month').setAttribute("class", "buttonNormal");
	document.getElementById('searchone').setAttribute("class", "buttonNormal");
	document.getElementById('searchyesterday').setAttribute("class", "buttonNormal");

	var status = document.getElementById('status').value ;
	document.getElementById('searchfrom').value = "<?php echo date('Y-m-d',strtotime(date('Y-m-d').'-1 days'));?>";
	document.getElementById('searchto').value = "<?php echo date('Y-m-d');?>";
	
	$.ajax({url:"lstemail-yesterday/button-2-days.php?pages="+page+"&str="+string+"&datecurrent="+datecurrent+"&twodays="+twodays+"&emails="+emails+"&statuss="+status,success:function(result){
			$("table#tbLogViewer").empty();
			$("table#tbLogViewer").append(result);
		}
	});
}
function onclickButton_7_days(page,string,datecurrent,sevendays,emails){
	document.getElementById('search').setAttribute("class", "buttonNormal");
	document.getElementById('searchAll').setAttribute("class", "buttonNormal");
	document.getElementById('search2day').setAttribute("class", "buttonNormal");
	document.getElementById('search1week').setAttribute("class", "buttonNormalchoose");
	document.getElementById('search1month').setAttribute("class", "buttonNormal");
	document.getElementById('searchone').setAttribute("class", "buttonNormal");
	document.getElementById('searchyesterday').setAttribute("class", "buttonNormal");

	var status = document.getElementById('status').value ;
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";
	
	$.ajax({url:"lstemail-yesterday/button-7-days.php?pages="+page+"&str="+string+"&datecurrent="+datecurrent+"&sevendays="+sevendays+"&emails="+emails+"&statuss="+status,success:function(result){
			$("table#tbLogViewer").empty();
			$("table#tbLogViewer").append(result);
		}
	});
}
function onclickButton_1_month(page,string,datecurrent,onemonth,emails){
	document.getElementById('search').setAttribute("class", "buttonNormal");
	document.getElementById('searchAll').setAttribute("class", "buttonNormal");
	document.getElementById('search2day').setAttribute("class", "buttonNormal");
	document.getElementById('search1week').setAttribute("class", "buttonNormal");
	document.getElementById('search1month').setAttribute("class", "buttonNormalchoose");
	document.getElementById('searchone').setAttribute("class", "buttonNormal");
	document.getElementById('searchyesterday').setAttribute("class", "buttonNormal");

	var status = document.getElementById('status').value ;
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";
	
	$.ajax({url:"lstemail-yesterday/button-1-month.php?pages="+page+"&str="+string+"&datecurrent="+datecurrent+"&one_month="+onemonth+"&emails="+emails+"&statuss="+status,success:function(result){
			$("table#tbLogViewer").empty();
			$("table#tbLogViewer").append(result);
		}
	});
}

function onclickButton_all(page,string,emails){
	document.getElementById('search').setAttribute("class", "buttonNormal");
	document.getElementById('searchAll').setAttribute("class", "buttonNormalchoose");
	document.getElementById('search2day').setAttribute("class", "buttonNormal");
	document.getElementById('search1week').setAttribute("class", "buttonNormal");
	document.getElementById('search1month').setAttribute("class", "buttonNormal");
	document.getElementById('searchone').setAttribute("class", "buttonNormal");
	document.getElementById('searchyesterday').setAttribute("class", "buttonNormal");

	var status = document.getElementById('status').value ;
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";
	
	$.ajax({url:"lstemail-yesterday/button-all.php?pages="+page+"&str="+string+"&emails="+emails+"&statuss="+status,success:function(result){
			$("table#tbLogViewer").empty();
			$("table#tbLogViewer").append(result);
		}
	});
}

function onclickButton_search_from_to(page,string,emails){
	document.getElementById('search').setAttribute("class", "buttonNormalchoose");
	document.getElementById('searchAll').setAttribute("class", "buttonNormal");
	document.getElementById('search2day').setAttribute("class", "buttonNormal");
	document.getElementById('search1week').setAttribute("class", "buttonNormal");
	document.getElementById('search1month').setAttribute("class", "buttonNormal");
	document.getElementById('searchone').setAttribute("class", "buttonNormal");
	document.getElementById('searchyesterday').setAttribute("class", "buttonNormal");

	var status = document.getElementById('status').value ;
	var from =  document.getElementById('searchfrom').value ;
	var to =  document.getElementById('searchto').value ;
	
	$.ajax({url:"lstemail-yesterday/button_search_from_to.php?pages="+page+"&str="+string+"&emails="+emails+"&statuss="+status+"&from="+from+"&to="+to,success:function(result){
			$("table#tbLogViewer").empty();
			$("table#tbLogViewer").append(result);
		}
	});
}

function sort_and_paging_lst_email_yesterday(page,string,flagDesc,search,from,to,yesterday,oneday,twodays,oneweek,onemonth,emails){
	var status = document.getElementById('status').value ;
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";
	
	$.ajax({url:"lstemail-yesterday/sort-paging-lstemail-yesterday.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,yesterday : yesterday,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails,status : status}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}
function sort_and_paging_lst_email_1_day(page,string,flagDesc,search,from,to,yesterday,oneday,twodays,oneweek,onemonth,emails){
	var status = document.getElementById('status').value ;
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";
	
	$.ajax({url:"lstemail-yesterday/sort-paging-lstEmail_1_Day.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,yesterday : yesterday,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails,status : status}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}
function sort_and_paging_lst_email_2_days(page,string,flagDesc,search,from,to,yesterday,oneday,twodays,oneweek,onemonth,emails){
	document.getElementById('searchfrom').value = "<?php echo date('Y-m-d',strtotime(date('Y-m-d').'-1 days'));?>";
	document.getElementById('searchto').value = "<?php echo date('Y-m-d');?>";
	
	var status = document.getElementById('status').value ;
	$.ajax({url:"lstemail-yesterday/sort-paging-lstEmail_2_Days.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,yesterday : yesterday,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails,status : status}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}
function sort_and_paging_lst_email_7_days(page,string,flagDesc,search,from,to,yesterday,oneday,twodays,oneweek,onemonth,emails){
	var status = document.getElementById('status').value ;
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";

	$.ajax({url:"lstemail-yesterday/sort-paging-lstEmail_7_Days.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,yesterday : yesterday,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails,status : status}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}
function sort_and_paging_lst_email_1_months(page,string,flagDesc,search,from,to,yesterday,oneday,twodays,oneweek,onemonth,emails){
	var status = document.getElementById('status').value ;
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";

	$.ajax({url:"lstemail-yesterday/sort-paging-lstEmail_1_Month.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,yesterday : yesterday,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails,status : status}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}
function sort_and_paging_lst_email_all(page,string,flagDesc,search,from,to,yesterday,oneday,twodays,oneweek,onemonth,emails){
	var status = document.getElementById('status').value ;
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";
	
	$.ajax({url:"lstemail-yesterday/sort_and_paging_lst_email_all.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,yesterday : yesterday,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails,status : status}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}
function sort_and_paging_lst_email_searchfromto(page,string,flagDesc,search,from,to,yesterday,oneday,twodays,oneweek,onemonth,emails){
	var status = document.getElementById('status').value ;
	document.getElementById('searchfrom').value = "";
	document.getElementById('searchto').value = "";
	
	$.ajax({url:"lstemail-yesterday/sort_and_paging_lst_email_searchfromto.php", data : {pages : page,str : string,flagDesc : flagDesc,search : search,from : from,to : to,yesterday : yesterday,oneday : oneday,twodays : twodays,oneweek : oneweek,onemonth : onemonth,emails : emails,status : status}, success:function(result){
		$("table#tbLogViewer").empty();
		$("table#tbLogViewer").append(result);
	}});
}
</script>
<div class="maincon1">
	<div class="hbox">
		<h2>
		<?=$login?>
		</h2>
		<p>
		<?=$login1?>
		</p>
		<div class="seldown">
			<ul>
			<?php if ($role==0){?>
				<li class="hoso" style="float:left;">
		        	<a href="#" onclick="changePage('profile')" style="background:url(images/bg_aa.png) no-repeat; display:block; width:145px; height:71px"><span><?=$hoso?></span></a>
		        </li>
		        <li class="giayphep" style="float:left;">
		        	<a href="#" onclick="changePage('license')" style="background:url(images/bg_aa_normal.png) no-repeat; display:block; width:145px; height:71px"><span><?=$namelicense?></span></a>
		        </li>
			<?php }else if ($role==1){?>
				<li class="hoso" style="float:left;">
		        	<a href="#" onclick="changePage('profile')" style="background:url(images/bg_aa_normal.png) no-repeat; display:block; width:145px; height:71px"><span><?=$hoso?></span></a>
		        </li>
		        <li class="giayphep" style="float:left;">
		        	<a href="#" onclick="changePage('license')" style="background:url(images/bg_aa_normal.png) no-repeat; display:block; width:145px; height:71px"><span><?=$namelicense?></span></a>
		        </li>
		        <li class="server" style="float:left;">
		       	<a href="#" onclick="changePage('log_server')" style="background:url(images/bg_aa_normal.png) no-repeat; display:block; width:145px; height:71px;cursor: pointer;"><span><?=$logserver?></span></a>
		        </li>
		        <li class="viewer" style="float:left;">
		        	<a onclick="changePage('logviewer')" style="background:url(images/bg_aa.png) no-repeat; display:block; width:145px; height:71px"><span class="chooseViewer"><?=$logviewer?></span></a>
		        </li>
		        <li class="viewertoserver" style="float:left;">
		        	<a href="#"  onclick="changePage('log_viewertoserver')" style="background:url(images/bg_aa_normal.png) no-repeat; display:block; width:145px; height:71px"><span><?=$logviewertoserver?></span></a>
		        </li>
			<?php }?>
		    	
	  	  </ul>
		</div>
	</div>
</div>

<div style="text-align: center;">
<input id="buttonuserlogin" name="buttonuserlogin" value="<?php echo $userloging?>"
				  class="buttonNormalchoose" type="button" style="width: 150px;" onclick="onclickUserLogining();"/>
<input id="buttonuserloginday" name="buttonuserloginday" value="<?php echo $userloginday?>"
				  class="buttonNormal" type="button" style="width: 150px;" onclick="onclickUserLoginInDay();"/>
<input id="buttonlstemailyesterday" name="buttonlstemailyesterday" value="<?=$emailusedyesterday?>" 
					class="buttonNormal" type="button" style="width: 238px;" onclick="onclickListEmailUseYesterday();">	
</div>
<div style="height: 10px;"></div>
<div id="idlogviewer">


<div class="maind" style="padding-top: 15px;">
	<div id="logserver" style="padding-left: 40px;">
		<table width="100%" cellpadding="0" cellspacing="0" class="mtable" id="tbLogViewer">
			<thead>
				<tr>
					<td align="center" style="width: 4%;color: #696969;"><?php echo $no?></td>
					<td align="center"><a onclick="pagingLogingUser('<?=$page?>','email',1)" style="cursor: pointer;color: #027acc"><?php echo $email ?></a></td>
					<td align="center"><a onclick="pagingLogingUser('<?=$page?>','ins_time',1)" style="cursor: pointer;color: #027acc"><?php echo $logintime ?></a></td>
					<td align="center"><a onclick="pagingLogingUser('<?=$page?>','login',1)" style="cursor: pointer;color: #027acc"><?php echo $viewlogining?></a></td>
				</tr>
			</thead>
			<?php
			if(mysql_num_rows($selectuserlogin)>0){
				$i=0;
				
				while ($row = mysql_fetch_array($selectuserlogin)){
					if ( $i >= $page_start ){?>
				<tr>
						<td align="center" style="width: 4%;"><?php echo $i+1?></td>
						<td align="center"><a onclick="onclickDetailemail(<?=$row[id]?>,'<?=$row[email]?>');" style="color: #0099FF;cursor: pointer;"><?php echo $row[email] ?></a></td>
						<td align="center"><?php echo $row[ins_time] ?></td>
						<td align="center"><?php echo ($row[login] - $row[logout])?></td>
					</tr>
			<?php
					}
						$i++;
						if ($i >= $page_end){
							break;
						}
					}
				}
			?>
			
			<tr>
						<td colspan="8" class="rf-dt-shdr-c">
							<span style="padding:1px; display: inline-block;">
														
								<?php if ( $number_of_page > 1 ) 
								{ 
									if ($page==1)
										$p=2;
									else if ($page==$number_of_page)
										$p=$number_of_page-1;
									else $p=$page;
									if($page!=1){?>
										<a onclick="pagingLogingUser(<?=1?>,'<?=$str?>',0)"><span class='button_next'><?php echo "<<<";?></span> </a>
										<a onclick="pagingLogingUser(<?=($page-1)?>,'<?=$str?>',0)"><span class='button_next'><?php echo "<<";?></span> </a>
									<?php  }
									else{
										echo "<span class='button_next'><<<</span> "; 
										echo "<span class='button_next'><<</span> ";
									}
									for ( $i = $p-1; $i <= $p+1; $i++ ) {	
											if ($i<=$number_of_page && $i>0)
											
												if ($i==$page){
													echo "<span class='button_next'><b>".$i."</b></span>"; 
												}else{
												?>
													<a onclick="pagingLogingUser(<?=$i?>,'<?=$str?>',0)"><span class="button_next">
													<?php 
													echo $i;
													?>
													</span> </a>
													<?php 
												}
											?>
										
									<?php 
											}
										
										if($page!=$number_of_page){ ?>
											<a onclick="pagingLogingUser(<?=($page+1)?>,'<?=$str?>',0)"><span class='button_next'><?php echo ">>";?></span> </a>
											<a onclick="pagingLogingUser(<?=($number_of_page)?>,'<?=$str?>',0)"><span class='button_next'><?php echo ">>>";?></span> </a>
										<?php }
										else{
											echo "<span class='button_next'>>></span> ";
											echo "<span class='button_next'>>>></span> ";
										}
									}
								
									
									?>
																						
							</span>
						</td>
					</tr>
		</table>
	</div>
</div>
</div>
<?php mysql_close($connection);?>